package cn.djun.news.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author djun
 * @classname GlobalExceptionHandler
 * @description
 * @date 2020/11/23 10:18
 * @email 3170495286@qq.com
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public Object globalErrorHandler(HttpServletRequest request, Exception e) {
        Map<String, Object> retMap = new HashMap<>(1024);
        retMap.put("responseCode", 500);
        retMap.put("responseMsg", e.getMessage());
        retMap.put("data", "系统错误");
        retMap.put("url", request.getRequestURL());
        return retMap;
    }
}
